package cn.stylefeng.guns.modular.controller;


import cn.stylefeng.guns.base.pojo.page.LayuiPageFactory;
import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.modular.entity.BannerImg;
import cn.stylefeng.guns.modular.service.IBannerImgService;
import cn.stylefeng.guns.modular.util.Result;
import cn.stylefeng.roses.core.reqres.response.ResponseData;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.Banner;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import org.springframework.web.servlet.ModelAndView;

/**
 * <p>
 * 广告图片表 前端控制器
 * </p>
 *
 * @author XiangTianGe
 * @since 2020-04-15
 */
@Controller
@RequestMapping("/banner")
public class BannerImgController {

    private static String PREFIX = "/banner/";

    @Autowired
    private IBannerImgService iBannerImgService;

    /**
     * 跳转广告banner 首页
     */
    @RequestMapping
    public String index() {
        return PREFIX + "banners.html";
    }

    /**
     * 跳转广告banner 添加
     */
    @RequestMapping("add")
    public String add() {
        return PREFIX + "banner_add.html";
    }

    /**
     * 跳转广告banner 修改
     */
    @RequestMapping("edit/{id}")
    public ModelAndView edit(@PathVariable Long id) {
        ModelAndView edit = iBannerImgService.edit(id);
        edit.setViewName(PREFIX + "banner_edit.html");
        return edit;
    }

    /**
     * banner 列表
     */
    @RequestMapping("list")
    @ResponseBody
    public LayuiPageInfo list(Integer type) {
        //获取分页参数
        Page page = LayuiPageFactory.defaultPage();

        return iBannerImgService.getList(type, page);
    }

    /**
     * 添加广告banner
     */
    @RequestMapping("add-banner")
    @ResponseBody
    public ResponseData addBanner(@RequestBody BannerImg bannerImg) {
        return iBannerImgService.addBanner(bannerImg);
    }

    /**
     * 修改广告banner
     */
    @RequestMapping("edit-banner")
    @ResponseBody
    public ResponseData editBanner(@RequestBody BannerImg bannerImg) {
        return iBannerImgService.editBanner(bannerImg);
    }

    /**
     * 删除广告banner
     */
    @ResponseBody
    @RequestMapping("delete/{id}")
    public ResponseData delete(@PathVariable Long id) {
        return iBannerImgService.delete(id);
    }


    @ResponseBody
    @RequestMapping("query/{id}")
    public ResponseData queryById(@PathVariable Long id) {
        return iBannerImgService.queryById(id);
    }
}

